package com.igeek.ch02.dao;

import com.igeek.ch02.entity.User;
import com.igeek.ch02.utils.JDBCUtilsByC3P0;

import java.sql.SQLException;
/*
 *@author wangpeng
 *2023/7/26 2:08
 *@description TODO
 */


public class UserDao extends BaseDao<User> {

    //通过姓名和地址查询用户信息
    public User findOne(String username , String address) throws SQLException {
        String sql = "select * from user where username = ? and address = ?";
        User user = this.selectOne(JDBCUtilsByC3P0.getConn(), sql, User.class, username, address);

        return user;
    }

    //插入用户信息
    public int insert(User user) throws SQLException {
        String sql = "insert into user values(null,?,?,?,?)";
        int i = this.update(JDBCUtilsByC3P0.getConn() , sql , user.getUsername() , user.getBirthday() ,
                user.getSex() , user.getAddress());
        return i;
    }
    //通过姓名查询用户信息
    public User findOne(String username) throws SQLException {
        String sql = "select * from user where username = ?";
        User user = this.selectOne(JDBCUtilsByC3P0.getConn(), sql, User.class, username);
        return user;
    }
}

